<template>
    <div>
        <el-card shadow="never">
            <el-button type="primary" icon="el-icon-download" style="margin-bottom: 10px">下载全部资料</el-button>
            <!-- 表格 -->
            <el-table :data="tableData" border style="font-size: 15px; width: 80%">
                <el-table-column prop="zlmc" label="文件名称"></el-table-column>
                <el-table-column prop="TIMESTAMP" label="时间"> </el-table-column>
                <el-table-column label="操作" min-width="80">
                    <template slot-scope="scope">
                        <el-button type="error" icon="el-icon-delete" size="mini" @click="delListItem(scope.row)">删除 </el-button>
                        <el-button type="error" icon="el-icon-download" size="mini" @click="downLoadListItem(scope.row)">下载 </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
import { getProjectList, delProjectList, getProjectDownLoad } from '@/api/backStage.js';
import { mapState } from 'vuex';
export default {
    props: ['rowObj', 'tabRow'],
    data() {
        return {
            tableData: [],
            downList: [],
            xmbm: ''
        };
    },
    computed: {
        // ...mapState(['applyFor'])
        ...mapState({
            flag: state => {
                return state.applyFor.listFlag;
            }
            //     basicJbxx: (state) => {
            //         return state.applyFor;
            //     }
        })
    },
    mounted() {
        this.getGcpList();
        // this.downLoadListItem();
    },

    methods: {
        // 获取列表
        async getGcpList() {
            if (this.flag == 'tabs') {
                const res = await getProjectList({
                    token: this.$store.state.user.token,
                    xmid: this.tabRow.xmid
                });
                if (res.code == 'succ') {
                    this.tableData = res.result;
                } else {
                    this.tableData = [];
                    // this.$message.error(res.message);
                }
            } else if (this.flag == 'apply') {
                const res = await getProjectList({
                    token: this.$store.state.user.token,
                    xmid: this.rowObj.xmid
                });
                if (res.code == 'succ') {
                    this.tableData = res.result;
                } else {
                    this.tableData = [];
                    // this.$message.error(res.message);
                }
            }
        },
        // 获取下载列表
        async downLoadListItem(row) {
            const res = await getProjectDownLoad({
                token: this.$store.state.user.token,
                xmid: row.xmid
            });
            if (res.code == 'succ') {
                this.downList = res.result;
                this.downList.forEach(item => {
                    window.open(item.zlurl);
                });
                this.$message.success(res.message);
            } else {
                // this.$message.error(res.message);
            }
        },
        // 删除
        async delListItem(row) {
            const res = await delProjectList({
                token: this.$store.state.user.token,
                xmid: row.xmid
            });
            if (res.code == 'succ') {
                this.$message.success(res.message);
                this.getGcpList();
            } else {
                this.$message.error(res.message);
            }
        }
    }
};
</script>

<style scoped></style>
